package commons;

import java.util.List;

/**
 * @author Jiang Jining
 * @since 2023-06-08 23:46
 */
public class LinkedListHelper {
    public static ListNode buildLinkedList(List<Integer> input) {
        if (input == null || input.isEmpty()) {
            return null;
        }
        ListNode dummy = new ListNode();
        ListNode head = dummy;
        for (Integer i : input) {
            dummy.next = new ListNode(i);
            dummy = dummy.next;
        }
        return head.next;
    }
    
    public static ListNode buildLinkedList(int[] input) {
        if (input == null || input.length == 0) {
            return null;
        }
        ListNode dummy = new ListNode();
        ListNode head = dummy;
        for (Integer i : input) {
            dummy.next = new ListNode(i);
            dummy = dummy.next;
        }
        return head.next;
    }
}
